﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using spbtzb;

public partial class FileDownload : System.Web.UI.Page
{
    protected string strConnection = spbtzb.ConString.ConnString;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {         
                BindTopList();
                this.lbCurPage.Text = "1";
                BindList();               
                BindNotice();
        }
    }
    protected void BindTopList()
    {
        DataTable dt = AccessHelper.ExecuteDataTable(strConnection, CommandType.Text,
                            "SELECT TOP 10  *  FROM FileList where IsDisplay = true");
        if (dt == null) return;
        rpTopList.DataSource = dt;
        rpTopList.DataBind();
    }


    protected void BindList()
    {
        // edit by shiney       
        DataTable dt = AccessHelper.ExecuteDataTable(strConnection, CommandType.Text,
                            "SELECT *  FROM FileList where IsDisplay = true");
        //if (dt == null) return;
        if (dt.Rows.Count == 0)
        {
            dvEmpty.InnerHtml += "此栏目暂无信息";
            dvbtn.Visible = false;
        }
        if (dt.Rows.Count > 0) dvbtn.Visible = true;

        PagedDataSource ps = new PagedDataSource();
        ps.AllowPaging = true;
        ps.PageSize = 10;
        rpList.DataSource = ps;
        ps.CurrentPageIndex = Convert.ToInt32(this.lbCurPage.Text) - 1;
        ps.DataSource = dt.DefaultView;

        this.btnPreviousPage.Enabled = true;
        this.btnNextPage.Enabled = true;
        if (ps.CurrentPageIndex == 0)
        {
            this.btnPreviousPage.Enabled = false;
        }
        if (ps.CurrentPageIndex == ps.PageCount - 1)
        {
            this.btnNextPage.Enabled = false;
        }
        rpList.DataBind();

    }
    //protected void BindControl()
    //{
    //    string type = ViewState["type"].ToString();
    //    string parentCode = Common.GetParentTypeCode(type);
    //    ltType.Text = Common.GetTypeNameByCode(type);
    //    this.Page.Title = ltType.Text;
    //    if (string.IsNullOrEmpty(parentCode))
    //    {
    //        dvNav.InnerHtml += "<a href='ContentList.aspx?type=" + type + "'>" + ltType.Text.ToString() + "</a>";
    //    }
    //    else
    //    {
    //        string parentName = Common.GetTypeNameByCode(parentCode);
    //        dvNav.InnerHtml += "<a href='ContentType.aspx?type=" + parentCode + "'>" + parentName +
    //                           "</a>&nbsp;>>&nbsp;<a href='ContentList.aspx?type=" + type + "'>" + ltType.Text.ToString() + "</a>";
    //    }
    //}
    protected void BindNotice()
    {
        DataTable dt = AccessHelper.ExecuteDataTable(strConnection, CommandType.Text,
        "SELECT TOP 5 ID, Title, CreateTime FROM Contents WHERE typecode = 'WZGG' Order By CreateTime DESC,ID DESC");
        if (dt == null) return;
        rpNotice.DataSource = dt;
        rpNotice.DataBind();
    }
    protected string CutString(string title)
    {
        return Common.CutString(title);
    }


    protected void btnNextPage_Click(object sender, System.EventArgs e)
    {
        this.lbCurPage.Text = Convert.ToString(Convert.ToInt32(this.lbCurPage.Text) + 1);
        this.BindList();       
    }

    protected void btnPreviousPage_Click(object sender, System.EventArgs e)
    {
        this.lbCurPage.Text = Convert.ToString(Convert.ToInt32(this.lbCurPage.Text) - 1);
        this.BindList();       
    }
}
